package md.frolov.bible.initializers;

public class TagStack{
	private String[] objs = new String[30];
	private int size = 0;
	
	public void empty() {
		size = 0;
	}

	public String peek() {
		if(size==0) throw new IllegalStateException();
		return (String) objs[size-1];
	}

	public String pop() {
		if(size == 0) throw new IllegalStateException();
		size--;
		return objs[size];
	}

	public String push(String item) {
		if(size==objs.length) expand();
		objs[size]=item;
		size++;
		return item;
	}

	private void expand(){
		expand(30);
	}
	
	private void expand(int exp){
		System.out.println("expanding");
		String[] oldObjs = objs;
		objs = new String[objs.length+exp];
		for(int i=0;i<size;i++){
			objs[i] = oldObjs[i];
		}
	}

	public boolean isEmpty() {
		return size==0;
	}

	public int size() {
		return size;
	}
	
}
